﻿using Data.Service.Service;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Data.Service
{
    public class Intelligence_AutoAppraiseData
    {
        public static SYTDataBaseEntities db = new SYTDataBaseEntities();
        //获取用户评价设置
        public static Intelligence_AutoAppraise GetAutoAppraise(string memberId)
        {
            Intelligence_AutoAppraise autoAppraise = db.Intelligence_AutoAppraise.Where(M => M.MemberId == memberId).FirstOrDefault();

            if (autoAppraise != null)
            {
                return autoAppraise;
            }
            else
            {
                Intelligence_AutoAppraise newAutoAppraise = new Intelligence_AutoAppraise();
                newAutoAppraise.IsAutoAppraise = false;
                newAutoAppraise.AppraiseContents = "你好，感谢你的惠顾！";
                newAutoAppraise.MemberId = memberId;
                newAutoAppraise.CreateTime = DateTime.Now;
                newAutoAppraise.UpdateTime = DateTime.Now;

                AddAutoAppraise(newAutoAppraise);//添加的数据库
                return newAutoAppraise;
            }
        }

        //修改数据
        public static bool UpdateAutoAppraise(Intelligence_AutoAppraise autoAppraise)
        {
            return BaseServer<Intelligence_AutoAppraise>.UpdateEntity(autoAppraise);
        }

        //添加一条数据
        public static bool AddAutoAppraise(Intelligence_AutoAppraise autoAppraise)
        {
            return BaseServer<Intelligence_AutoAppraise>.AddEntity(autoAppraise);
        }


        //获取当日和历史评价次数
        public static int GetAutoAppraiseCount(int mark, string memberId)
        {
            if (mark == 1)
            {
                return db.Intelligence_AutoAppraise.Where(M => M.MemberId == memberId).Count();
            }
            else
            {
                DateTime crruntTime = DateTime.Now;
                return db.Intelligence_AutoAppraise.Where(M => M.MemberId == memberId && M.CreateTime < DateTime.Now && M.CreateTime > crruntTime.Date).Count();
            }
        }

    }
}
